import { Injectable } from '@nestjs/common';
import { Like, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Admin } from './entityes/admin.entity';

@Injectable()
export class AdminService {
    constructor(@InjectRepository(Admin) private readonly admin: Repository<Admin>) {}

    addAdmin(admin:any){
        const data = new Admin();
        data.name = admin.name;
        data.age = admin.age;
        data.skill = admin.skill;
        return this.admin.save(data);
    }

    delAdmin(id:number){
        return this.admin.delete(id);
    }

    updateAdmin(admin:any){
        let data = new Admin();
        data.name = admin.name;
        data.age = admin.age;
        data.skill = admin.skill;
        return this.admin.update(admin.id,data);
    }

    getAdmin(){
        return this.admin.find();
    }

    getAdminName(name:string){
        return this.admin.find({
            where:{
                name:Like(`%${name}%`)
            }
        });
    }
    
}
